package com.heima.App;

import com.heima.mapper.UserMapper;
import com.heima.pojo.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.SQLException;

public class AppMysql {
    public static void main(String[] args) throws SQLException {
        ClassPathXmlApplicationContext cpac =
                new ClassPathXmlApplicationContext("ApplicationContext-Jdbc.xml");

        DataSource dataSource = (DataSource) cpac.getBean("dataSource");

        //测试
        boolean closed = dataSource.getConnection().isClosed();
        //false即为连接成功
        System.out.println(closed);

        UserMapper userMapper = (UserMapper) cpac.getBean("userMapper");
        User user = userMapper.seleteByid(2);
        System.out.println(user);

        cpac.close();
    }
}
